package cn.wangqi.personal.dao;

import cn.wangqi.personal.domain.BlogTagArticle;
import cn.wangqi.personal.util.Page;
import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 *created by admin  2017-10-17 02:42:41
 */
@Repository
public class BlogTagArticleDao{
    private final String NAMESPACE = this.getClass().getName() + ".";
    private Logger logger = Logger.getLogger(BlogTagArticleDao.class);
    @Resource
    protected SqlSessionTemplate mainSqlSession;

    public List<BlogTagArticle> listBlogTagArticleByArticleId(int articleId){
        Map<String, Object> params = new HashMap<>();
        params.put("articleId",articleId);
        return mainSqlSession.selectList(NAMESPACE + "listBlogTagArticleByArticleId", params);
    }




    public void saveBlogTagArticle(BlogTagArticle blogTagArticle) {
        mainSqlSession.insert(NAMESPACE + "saveBlogTagArticle", blogTagArticle);
    }

    public void saveBlogTagArticle(List<BlogTagArticle> blogTagArticle) {
        mainSqlSession.insert(NAMESPACE + "saveBlogTagArticleList", blogTagArticle);
    }

    public void deleteBlogTagArticleById(int blogTagArticleId) {
        mainSqlSession.delete(NAMESPACE + "deleteBlogTagArticleById", blogTagArticleId);
    }

    public BlogTagArticle findBlogTagArticleById(int blogTagArticleId){
        return mainSqlSession.selectOne(NAMESPACE + "findBlogTagArticleById", blogTagArticleId);
    }

    public List<BlogTagArticle> listBlogTagArticle(int blogTagArticleId, Page page){
        Map<String, Object> params = new HashMap<>();
        params.put("page",page);
        return mainSqlSession.selectList(NAMESPACE + "listBlogTagArticle", params);
    }

    public int countBlogTagArticle(){
        Map<String, Object> params = new HashMap<>();
        return mainSqlSession.selectOne(NAMESPACE + "totalBlogTagArticle",params);
    }

    public void updateBlogTagArticle(BlogTagArticle blogTagArticle){
        mainSqlSession.update(NAMESPACE + "updateBlogTagArticle", blogTagArticle);
    }

}
